#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <stdexcept>

enum class Type {
    CHAR,
    INT,
    FLOAT
};

class DataType {
private:
    Type type;
    union {
        char ch;
        int i;
        float f;
    } data;

public:
    DataType(char c) : type(Type::CHAR) {
        data.ch = c;
    }

    DataType(int i) : type(Type::INT) {
        data.i = i;
    }

    DataType(float f) : type(Type::FLOAT) {
        data.f = f;
    }

    ~DataType() {}

    Type getType() const {
        return type;
    }

    char getChar() const {
        if (type != Type::CHAR) {
            throw std::runtime_error("Data type is not CHAR");
        }
        return data.ch;
    }

    int getInt() const {
        if (type != Type::INT) {
            throw std::runtime_error("Data type is not INT");
        }
        return data.i;
    }

    float getFloat() const {
        if (type != Type::FLOAT) {
            throw std::runtime_error("Data type is not FLOAT");
        }
        return data.f;
    }

    void display() const {
        switch (type) {
        case Type::CHAR:
            std::cout << "CHAR: " << data.ch << std::endl;
            break;
        case Type::INT:
            std::cout << "INT: " << data.i << std::endl;
            break;
        case Type::FLOAT:
            std::cout << "FLOAT: " << data.f << std::endl;
            break;
        }
    }
};

int main3() {
    DataType charData('A');
    DataType intData(42);
    DataType floatData(3.14f);

    std::cout << "Displaying DataType objects:" << std::endl;
    charData.display();
    intData.display();
    floatData.display();

    std::cout << "\nGetting data values:" << std::endl;
    std::cout << "Char data: " << charData.getChar() << std::endl;
    std::cout << "Int data: " << intData.getInt() << std::endl;
    std::cout << "Float data: " << floatData.getFloat() << std::endl;

    return 0;
}
